PDA

View Full Version : Solved: VBA Coding Question



jo15765
04-03-2012, 06:16 PM
I am running the EXACT same Procedure but with two different names. Let's call it procedure1 and procedure2. Procedure1 is set up like this

Sub Procedure1(AHName As String)
sql = "Select * FROM tbl_Uno"

Set cn = New ADODB.Connection

cn.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=P:\Database\Test\" & AHName & "\\" & AHName & ".mdb;"


And Procedure 2


Sub Procedure2()

txtAHName = UserForm1.txt1.Text

sql = "Select * FROM tbl_Uno"

Set cn = New ADODB.Connection

cn.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=P:\Database\Test\" & txtAHName & "\\" & txtAHName & ".mdb;"

As you can see they both run the same SQL procedure, but one gets the variable passed from the main procedure whereas the other gets the variable passed from the value of a textbox. Is there a way to combine those two procedures and say that if the value passed from the main procedure is null, THEN check the value of the textbox if they are both null then exit procedure (I'm assuming that piece would be Resume Next).

Bob Phillips
04-04-2012, 01:05 AM
Sub Procedure1(AHName As String)

If AHName = "" Then

AHName = UserForm1.txt1.Text
If AHName = "" Then

MsgBox "No parameter available"
Exit Sub
End If
End If
Sql = "Select * FROM tbl_Uno"

Set cn = New ADODB.Connection

cn.Open "Driver={Microsoft Access Driver ](*.mdb)};Dbq=P:\Database\Test\" & AHName & "\\" & AHName & ".mdb;"
End Sub

jo15765
04-04-2012, 04:53 AM
So Stinkin simple, I don't know why I didn't see that!!! Thank you tremendously for the prompt response and assistance!