PC Review


Reply
Thread Tools Rate Thread

Passing a Variable, or Passing a Parameter

 
 
ryguy7272
Guest
Posts: n/a
 
      20th May 2008
I’d like to take a value from a combo box and load it into a table named
tblLoginSettings. I am trying to figure out how to get the value into a
field named ‘CurrentUser’ into the table named tblLoginSettings. Not sure
how to start. I guess it would be done by passing a variable, or passing a
parameter, or something like that. Can someone give me some code to do this,
or refer me to a web site that ex\plains how to do this?

Thanks so much,
Ryan---


--
RyGuy
 
Reply With Quote
 
 
 
 
Klatuu
Guest
Posts: n/a
 
      20th May 2008
I assume the combo box will be an unbound control and that tblLoginSettings
is not part of the form's record source. Use the combo's After Update event:

Dim strSQL As String

strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
Me.MyCombName & """ AS dummy;"
Currentdb.Execute strSQL, dbFailOnError

The above syntax assumes CurrentUser is a text field.
--
Dave Hargis, Microsoft Access MVP


"ryguy7272" wrote:

> I’d like to take a value from a combo box and load it into a table named
> tblLoginSettings. I am trying to figure out how to get the value into a
> field named ‘CurrentUser’ into the table named tblLoginSettings. Not sure
> how to start. I guess it would be done by passing a variable, or passing a
> parameter, or something like that. Can someone give me some code to do this,
> or refer me to a web site that ex\plains how to do this?
>
> Thanks so much,
> Ryan---
>
>
> --
> RyGuy

 
Reply With Quote
 
 
 
 
ryguy7272
Guest
Posts: n/a
 
      20th May 2008
Thanks for the look Dave! The code looks like it should work, but it
actually does not work.

The error message reads:
Compile Error:
Method or Data Member not Found

The Private line is yellow and the following is highlighted:
..MyCombName


Yes, CurrentUser is of Data Type text.

The Row Source on the ComboBox is:
SELECT DISTINCT tblLogin.Login FROM tblLogin ORDER BY tblLogin.Login;

Also, After Update is set to:
[Event Procedure]
(not sure if that makes a difference or not...)

The code under the UserForm is as follows;
'Private Sub cboEmployee_BeforeUpdate(Cancel As Integer)
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field

Dim strSQL As String

strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
Me.MyCombName & """ AS dummy;"
CurrentDb.Execute strSQL, dbFailOnError

Me.txtPassword.SetFocus

End Sub

Any additional thoughts?
Thanks,
Ryan---


--
RyGuy


"Klatuu" wrote:

> I assume the combo box will be an unbound control and that tblLoginSettings
> is not part of the form's record source. Use the combo's After Update event:
>
> Dim strSQL As String
>
> strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> Me.MyCombName & """ AS dummy;"
> Currentdb.Execute strSQL, dbFailOnError
>
> The above syntax assumes CurrentUser is a text field.
> --
> Dave Hargis, Microsoft Access MVP
>
>
> "ryguy7272" wrote:
>
> > I’d like to take a value from a combo box and load it into a table named
> > tblLoginSettings. I am trying to figure out how to get the value into a
> > field named ‘CurrentUser’ into the table named tblLoginSettings. Not sure
> > how to start. I guess it would be done by passing a variable, or passing a
> > parameter, or something like that. Can someone give me some code to do this,
> > or refer me to a web site that ex\plains how to do this?
> >
> > Thanks so much,
> > Ryan---
> >
> >
> > --
> > RyGuy

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      21st May 2008
Running the code below gives me a syntax error:
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus

Dim strSQL As String

strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
Me.cboEmployee & """ AS dummy;"
CurrentDb.Execute strSQL, dbFailOnError

End Sub


Error is:
Run-time error 3134:
Syntax Error in INSERT INTO statement.

This line is highlighted:
CurrentDb.Execute strSQL, dbFailOnError

What causes this error?

Regards,
Ryan---

--
RyGuy


"ryguy7272" wrote:

> Thanks for the look Dave! The code looks like it should work, but it
> actually does not work.
>
> The error message reads:
> Compile Error:
> Method or Data Member not Found
>
> The Private line is yellow and the following is highlighted:
> .MyCombName
>
>
> Yes, CurrentUser is of Data Type text.
>
> The Row Source on the ComboBox is:
> SELECT DISTINCT tblLogin.Login FROM tblLogin ORDER BY tblLogin.Login;
>
> Also, After Update is set to:
> [Event Procedure]
> (not sure if that makes a difference or not...)
>
> The code under the UserForm is as follows;
> 'Private Sub cboEmployee_BeforeUpdate(Cancel As Integer)
> Private Sub cboEmployee_AfterUpdate()
> 'After selecting user name set focus to password field
>
> Dim strSQL As String
>
> strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> Me.MyCombName & """ AS dummy;"
> CurrentDb.Execute strSQL, dbFailOnError
>
> Me.txtPassword.SetFocus
>
> End Sub
>
> Any additional thoughts?
> Thanks,
> Ryan---
>
>
> --
> RyGuy
>
>
> "Klatuu" wrote:
>
> > I assume the combo box will be an unbound control and that tblLoginSettings
> > is not part of the form's record source. Use the combo's After Update event:
> >
> > Dim strSQL As String
> >
> > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > Me.MyCombName & """ AS dummy;"
> > Currentdb.Execute strSQL, dbFailOnError
> >
> > The above syntax assumes CurrentUser is a text field.
> > --
> > Dave Hargis, Microsoft Access MVP
> >
> >
> > "ryguy7272" wrote:
> >
> > > I’d like to take a value from a combo box and load it into a table named
> > > tblLoginSettings. I am trying to figure out how to get the value into a
> > > field named ‘CurrentUser’ into the table named tblLoginSettings. Not sure
> > > how to start. I guess it would be done by passing a variable, or passing a
> > > parameter, or something like that. Can someone give me some code to do this,
> > > or refer me to a web site that ex\plains how to do this?
> > >
> > > Thanks so much,
> > > Ryan---
> > >
> > >
> > > --
> > > RyGuy

 
Reply With Quote
 
Klatuu
Guest
Posts: n/a
 
      21st May 2008
My mistake, sorry. Should be:
strSQL = "INSERT INTO tblLoginSettings (CurrentUser) SELECT """ & _
Me.MyCombName & """ AS dummy;"

--
Dave Hargis, Microsoft Access MVP


"ryguy7272" wrote:

> Running the code below gives me a syntax error:
> Private Sub cboEmployee_AfterUpdate()
> 'After selecting user name set focus to password field
> Me.txtPassword.SetFocus
>
> Dim strSQL As String
>
> strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> Me.cboEmployee & """ AS dummy;"
> CurrentDb.Execute strSQL, dbFailOnError
>
> End Sub
>
>
> Error is:
> Run-time error 3134:
> Syntax Error in INSERT INTO statement.
>
> This line is highlighted:
> CurrentDb.Execute strSQL, dbFailOnError
>
> What causes this error?
>
> Regards,
> Ryan---
>
> --
> RyGuy
>
>
> "ryguy7272" wrote:
>
> > Thanks for the look Dave! The code looks like it should work, but it
> > actually does not work.
> >
> > The error message reads:
> > Compile Error:
> > Method or Data Member not Found
> >
> > The Private line is yellow and the following is highlighted:
> > .MyCombName
> >
> >
> > Yes, CurrentUser is of Data Type text.
> >
> > The Row Source on the ComboBox is:
> > SELECT DISTINCT tblLogin.Login FROM tblLogin ORDER BY tblLogin.Login;
> >
> > Also, After Update is set to:
> > [Event Procedure]
> > (not sure if that makes a difference or not...)
> >
> > The code under the UserForm is as follows;
> > 'Private Sub cboEmployee_BeforeUpdate(Cancel As Integer)
> > Private Sub cboEmployee_AfterUpdate()
> > 'After selecting user name set focus to password field
> >
> > Dim strSQL As String
> >
> > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > Me.MyCombName & """ AS dummy;"
> > CurrentDb.Execute strSQL, dbFailOnError
> >
> > Me.txtPassword.SetFocus
> >
> > End Sub
> >
> > Any additional thoughts?
> > Thanks,
> > Ryan---
> >
> >
> > --
> > RyGuy
> >
> >
> > "Klatuu" wrote:
> >
> > > I assume the combo box will be an unbound control and that tblLoginSettings
> > > is not part of the form's record source. Use the combo's After Update event:
> > >
> > > Dim strSQL As String
> > >
> > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > Me.MyCombName & """ AS dummy;"
> > > Currentdb.Execute strSQL, dbFailOnError
> > >
> > > The above syntax assumes CurrentUser is a text field.
> > > --
> > > Dave Hargis, Microsoft Access MVP
> > >
> > >
> > > "ryguy7272" wrote:
> > >
> > > > I’d like to take a value from a combo box and load it into a table named
> > > > tblLoginSettings. I am trying to figure out how to get the value into a
> > > > field named ‘CurrentUser’ into the table named tblLoginSettings. Not sure
> > > > how to start. I guess it would be done by passing a variable, or passing a
> > > > parameter, or something like that. Can someone give me some code to do this,
> > > > or refer me to a web site that ex\plains how to do this?
> > > >
> > > > Thanks so much,
> > > > Ryan---
> > > >
> > > >
> > > > --
> > > > RyGuy

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      21st May 2008
Thanks for following up Dave. This is the code that I am running in the Form
now:
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus

Dim strSQL As String

strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
Me.cboEmployee & """ AS text;"

End Sub

The error is gone, but now nothing happens. The CurrentUser in
tblLoginSettings stays the same. The value from the ComboBox is never
actually passed. I know VBA in Excel pretty well, but I don't know VBA in
Access well. The code looks right to me, but I just can't tell what is
wrong. Perhaps it could be a setting somewhere...on the Form on in the
tlbLoginSettings? I think we car egetting very close to a solution here.
Any additional thoughts on this?

Thanks for your time,
Ryan--



--
RyGuy


"Klatuu" wrote:

> My mistake, sorry. Should be:
> strSQL = "INSERT INTO tblLoginSettings (CurrentUser) SELECT """ & _
> Me.MyCombName & """ AS dummy;"
>
> --
> Dave Hargis, Microsoft Access MVP
>
>
> "ryguy7272" wrote:
>
> > Running the code below gives me a syntax error:
> > Private Sub cboEmployee_AfterUpdate()
> > 'After selecting user name set focus to password field
> > Me.txtPassword.SetFocus
> >
> > Dim strSQL As String
> >
> > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > Me.cboEmployee & """ AS dummy;"
> > CurrentDb.Execute strSQL, dbFailOnError
> >
> > End Sub
> >
> >
> > Error is:
> > Run-time error 3134:
> > Syntax Error in INSERT INTO statement.
> >
> > This line is highlighted:
> > CurrentDb.Execute strSQL, dbFailOnError
> >
> > What causes this error?
> >
> > Regards,
> > Ryan---
> >
> > --
> > RyGuy
> >
> >
> > "ryguy7272" wrote:
> >
> > > Thanks for the look Dave! The code looks like it should work, but it
> > > actually does not work.
> > >
> > > The error message reads:
> > > Compile Error:
> > > Method or Data Member not Found
> > >
> > > The Private line is yellow and the following is highlighted:
> > > .MyCombName
> > >
> > >
> > > Yes, CurrentUser is of Data Type text.
> > >
> > > The Row Source on the ComboBox is:
> > > SELECT DISTINCT tblLogin.Login FROM tblLogin ORDER BY tblLogin.Login;
> > >
> > > Also, After Update is set to:
> > > [Event Procedure]
> > > (not sure if that makes a difference or not...)
> > >
> > > The code under the UserForm is as follows;
> > > 'Private Sub cboEmployee_BeforeUpdate(Cancel As Integer)
> > > Private Sub cboEmployee_AfterUpdate()
> > > 'After selecting user name set focus to password field
> > >
> > > Dim strSQL As String
> > >
> > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > Me.MyCombName & """ AS dummy;"
> > > CurrentDb.Execute strSQL, dbFailOnError
> > >
> > > Me.txtPassword.SetFocus
> > >
> > > End Sub
> > >
> > > Any additional thoughts?
> > > Thanks,
> > > Ryan---
> > >
> > >
> > > --
> > > RyGuy
> > >
> > >
> > > "Klatuu" wrote:
> > >
> > > > I assume the combo box will be an unbound control and that tblLoginSettings
> > > > is not part of the form's record source. Use the combo's After Update event:
> > > >
> > > > Dim strSQL As String
> > > >
> > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > Me.MyCombName & """ AS dummy;"
> > > > Currentdb.Execute strSQL, dbFailOnError
> > > >
> > > > The above syntax assumes CurrentUser is a text field.
> > > > --
> > > > Dave Hargis, Microsoft Access MVP
> > > >
> > > >
> > > > "ryguy7272" wrote:
> > > >
> > > > > I’d like to take a value from a combo box and load it into a table named
> > > > > tblLoginSettings. I am trying to figure out how to get the value into a
> > > > > field named ‘CurrentUser’ into the table named tblLoginSettings. Not sure
> > > > > how to start. I guess it would be done by passing a variable, or passing a
> > > > > parameter, or something like that. Can someone give me some code to do this,
> > > > > or refer me to a web site that ex\plains how to do this?
> > > > >
> > > > > Thanks so much,
> > > > > Ryan---
> > > > >
> > > > >
> > > > > --
> > > > > RyGuy

 
Reply With Quote
 
Klatuu
Guest
Posts: n/a
 
      21st May 2008
You are not executing the SQL. All you are doing is building the SQL command.
Should be:

strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
Me.cboEmployee & """ AS text;"

Currentdb.Execute strSQL, dbFailOnError

--
Dave Hargis, Microsoft Access MVP


"ryguy7272" wrote:

> Thanks for following up Dave. This is the code that I am running in the Form
> now:
> Private Sub cboEmployee_AfterUpdate()
> 'After selecting user name set focus to password field
> Me.txtPassword.SetFocus
>
> Dim strSQL As String
>
> strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> Me.cboEmployee & """ AS text;"
>
> End Sub
>
> The error is gone, but now nothing happens. The CurrentUser in
> tblLoginSettings stays the same. The value from the ComboBox is never
> actually passed. I know VBA in Excel pretty well, but I don't know VBA in
> Access well. The code looks right to me, but I just can't tell what is
> wrong. Perhaps it could be a setting somewhere...on the Form on in the
> tlbLoginSettings? I think we car egetting very close to a solution here.
> Any additional thoughts on this?
>
> Thanks for your time,
> Ryan--
>
>
>
> --
> RyGuy
>
>
> "Klatuu" wrote:
>
> > My mistake, sorry. Should be:
> > strSQL = "INSERT INTO tblLoginSettings (CurrentUser) SELECT """ & _
> > Me.MyCombName & """ AS dummy;"
> >
> > --
> > Dave Hargis, Microsoft Access MVP
> >
> >
> > "ryguy7272" wrote:
> >
> > > Running the code below gives me a syntax error:
> > > Private Sub cboEmployee_AfterUpdate()
> > > 'After selecting user name set focus to password field
> > > Me.txtPassword.SetFocus
> > >
> > > Dim strSQL As String
> > >
> > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > Me.cboEmployee & """ AS dummy;"
> > > CurrentDb.Execute strSQL, dbFailOnError
> > >
> > > End Sub
> > >
> > >
> > > Error is:
> > > Run-time error 3134:
> > > Syntax Error in INSERT INTO statement.
> > >
> > > This line is highlighted:
> > > CurrentDb.Execute strSQL, dbFailOnError
> > >
> > > What causes this error?
> > >
> > > Regards,
> > > Ryan---
> > >
> > > --
> > > RyGuy
> > >
> > >
> > > "ryguy7272" wrote:
> > >
> > > > Thanks for the look Dave! The code looks like it should work, but it
> > > > actually does not work.
> > > >
> > > > The error message reads:
> > > > Compile Error:
> > > > Method or Data Member not Found
> > > >
> > > > The Private line is yellow and the following is highlighted:
> > > > .MyCombName
> > > >
> > > >
> > > > Yes, CurrentUser is of Data Type text.
> > > >
> > > > The Row Source on the ComboBox is:
> > > > SELECT DISTINCT tblLogin.Login FROM tblLogin ORDER BY tblLogin.Login;
> > > >
> > > > Also, After Update is set to:
> > > > [Event Procedure]
> > > > (not sure if that makes a difference or not...)
> > > >
> > > > The code under the UserForm is as follows;
> > > > 'Private Sub cboEmployee_BeforeUpdate(Cancel As Integer)
> > > > Private Sub cboEmployee_AfterUpdate()
> > > > 'After selecting user name set focus to password field
> > > >
> > > > Dim strSQL As String
> > > >
> > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > Me.MyCombName & """ AS dummy;"
> > > > CurrentDb.Execute strSQL, dbFailOnError
> > > >
> > > > Me.txtPassword.SetFocus
> > > >
> > > > End Sub
> > > >
> > > > Any additional thoughts?
> > > > Thanks,
> > > > Ryan---
> > > >
> > > >
> > > > --
> > > > RyGuy
> > > >
> > > >
> > > > "Klatuu" wrote:
> > > >
> > > > > I assume the combo box will be an unbound control and that tblLoginSettings
> > > > > is not part of the form's record source. Use the combo's After Update event:
> > > > >
> > > > > Dim strSQL As String
> > > > >
> > > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > > Me.MyCombName & """ AS dummy;"
> > > > > Currentdb.Execute strSQL, dbFailOnError
> > > > >
> > > > > The above syntax assumes CurrentUser is a text field.
> > > > > --
> > > > > Dave Hargis, Microsoft Access MVP
> > > > >
> > > > >
> > > > > "ryguy7272" wrote:
> > > > >
> > > > > > I’d like to take a value from a combo box and load it into a table named
> > > > > > tblLoginSettings. I am trying to figure out how to get the value into a
> > > > > > field named ‘CurrentUser’ into the table named tblLoginSettings. Not sure
> > > > > > how to start. I guess it would be done by passing a variable, or passing a
> > > > > > parameter, or something like that. Can someone give me some code to do this,
> > > > > > or refer me to a web site that ex\plains how to do this?
> > > > > >
> > > > > > Thanks so much,
> > > > > > Ryan---
> > > > > >
> > > > > >
> > > > > > --
> > > > > > RyGuy

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      21st May 2008
Oh! It's starting to make sense. Maybe I need to use a Query, rather than a
Table. Right now I have a Table named tblLoginSettings. It has a Field,
which is Data Type AutoNumber and another Field, which is Date Type Text.
That's all. i don't use a Query for this. Should l I use a Query for this?
I only have two Queries in this DB and they are actually related to this
Table. I was hoping to get the value from the ComboBox, pass it to the
Table, named tblLoginSettings, and pass that to one of the two Queries,
depending on what is entered into the Table. Does that make any sense? Is
there a better way of doing this?

Please let me know what to do.


Thanks,
Ryan--

--
RyGuy


"Klatuu" wrote:

> You are not executing the SQL. All you are doing is building the SQL command.
> Should be:
>
> strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> Me.cboEmployee & """ AS text;"
>
> Currentdb.Execute strSQL, dbFailOnError
>
> --
> Dave Hargis, Microsoft Access MVP
>
>
> "ryguy7272" wrote:
>
> > Thanks for following up Dave. This is the code that I am running in the Form
> > now:
> > Private Sub cboEmployee_AfterUpdate()
> > 'After selecting user name set focus to password field
> > Me.txtPassword.SetFocus
> >
> > Dim strSQL As String
> >
> > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > Me.cboEmployee & """ AS text;"
> >
> > End Sub
> >
> > The error is gone, but now nothing happens. The CurrentUser in
> > tblLoginSettings stays the same. The value from the ComboBox is never
> > actually passed. I know VBA in Excel pretty well, but I don't know VBA in
> > Access well. The code looks right to me, but I just can't tell what is
> > wrong. Perhaps it could be a setting somewhere...on the Form on in the
> > tlbLoginSettings? I think we car egetting very close to a solution here.
> > Any additional thoughts on this?
> >
> > Thanks for your time,
> > Ryan--
> >
> >
> >
> > --
> > RyGuy
> >
> >
> > "Klatuu" wrote:
> >
> > > My mistake, sorry. Should be:
> > > strSQL = "INSERT INTO tblLoginSettings (CurrentUser) SELECT """ & _
> > > Me.MyCombName & """ AS dummy;"
> > >
> > > --
> > > Dave Hargis, Microsoft Access MVP
> > >
> > >
> > > "ryguy7272" wrote:
> > >
> > > > Running the code below gives me a syntax error:
> > > > Private Sub cboEmployee_AfterUpdate()
> > > > 'After selecting user name set focus to password field
> > > > Me.txtPassword.SetFocus
> > > >
> > > > Dim strSQL As String
> > > >
> > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > Me.cboEmployee & """ AS dummy;"
> > > > CurrentDb.Execute strSQL, dbFailOnError
> > > >
> > > > End Sub
> > > >
> > > >
> > > > Error is:
> > > > Run-time error 3134:
> > > > Syntax Error in INSERT INTO statement.
> > > >
> > > > This line is highlighted:
> > > > CurrentDb.Execute strSQL, dbFailOnError
> > > >
> > > > What causes this error?
> > > >
> > > > Regards,
> > > > Ryan---
> > > >
> > > > --
> > > > RyGuy
> > > >
> > > >
> > > > "ryguy7272" wrote:
> > > >
> > > > > Thanks for the look Dave! The code looks like it should work, but it
> > > > > actually does not work.
> > > > >
> > > > > The error message reads:
> > > > > Compile Error:
> > > > > Method or Data Member not Found
> > > > >
> > > > > The Private line is yellow and the following is highlighted:
> > > > > .MyCombName
> > > > >
> > > > >
> > > > > Yes, CurrentUser is of Data Type text.
> > > > >
> > > > > The Row Source on the ComboBox is:
> > > > > SELECT DISTINCT tblLogin.Login FROM tblLogin ORDER BY tblLogin.Login;
> > > > >
> > > > > Also, After Update is set to:
> > > > > [Event Procedure]
> > > > > (not sure if that makes a difference or not...)
> > > > >
> > > > > The code under the UserForm is as follows;
> > > > > 'Private Sub cboEmployee_BeforeUpdate(Cancel As Integer)
> > > > > Private Sub cboEmployee_AfterUpdate()
> > > > > 'After selecting user name set focus to password field
> > > > >
> > > > > Dim strSQL As String
> > > > >
> > > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > > Me.MyCombName & """ AS dummy;"
> > > > > CurrentDb.Execute strSQL, dbFailOnError
> > > > >
> > > > > Me.txtPassword.SetFocus
> > > > >
> > > > > End Sub
> > > > >
> > > > > Any additional thoughts?
> > > > > Thanks,
> > > > > Ryan---
> > > > >
> > > > >
> > > > > --
> > > > > RyGuy
> > > > >
> > > > >
> > > > > "Klatuu" wrote:
> > > > >
> > > > > > I assume the combo box will be an unbound control and that tblLoginSettings
> > > > > > is not part of the form's record source. Use the combo's After Update event:
> > > > > >
> > > > > > Dim strSQL As String
> > > > > >
> > > > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > > > Me.MyCombName & """ AS dummy;"
> > > > > > Currentdb.Execute strSQL, dbFailOnError
> > > > > >
> > > > > > The above syntax assumes CurrentUser is a text field.
> > > > > > --
> > > > > > Dave Hargis, Microsoft Access MVP
> > > > > >
> > > > > >
> > > > > > "ryguy7272" wrote:
> > > > > >
> > > > > > > I’d like to take a value from a combo box and load it into a table named
> > > > > > > tblLoginSettings. I am trying to figure out how to get the value into a
> > > > > > > field named ‘CurrentUser’ into the table named tblLoginSettings. Not sure
> > > > > > > how to start. I guess it would be done by passing a variable, or passing a
> > > > > > > parameter, or something like that. Can someone give me some code to do this,
> > > > > > > or refer me to a web site that ex\plains how to do this?
> > > > > > >
> > > > > > > Thanks so much,
> > > > > > > Ryan---
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > RyGuy

 
Reply With Quote
 
Klatuu
Guest
Posts: n/a
 
      22nd May 2008
Can you describe what is it you want to do? I guess I am not clear on the
intent. If you can tell me what, perhaps I can tell you how.
--
Dave Hargis, Microsoft Access MVP


"ryguy7272" wrote:

> Oh! It's starting to make sense. Maybe I need to use a Query, rather than a
> Table. Right now I have a Table named tblLoginSettings. It has a Field,
> which is Data Type AutoNumber and another Field, which is Date Type Text.
> That's all. i don't use a Query for this. Should l I use a Query for this?
> I only have two Queries in this DB and they are actually related to this
> Table. I was hoping to get the value from the ComboBox, pass it to the
> Table, named tblLoginSettings, and pass that to one of the two Queries,
> depending on what is entered into the Table. Does that make any sense? Is
> there a better way of doing this?
>
> Please let me know what to do.
>
>
> Thanks,
> Ryan--
>
> --
> RyGuy
>
>
> "Klatuu" wrote:
>
> > You are not executing the SQL. All you are doing is building the SQL command.
> > Should be:
> >
> > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > Me.cboEmployee & """ AS text;"
> >
> > Currentdb.Execute strSQL, dbFailOnError
> >
> > --
> > Dave Hargis, Microsoft Access MVP
> >
> >
> > "ryguy7272" wrote:
> >
> > > Thanks for following up Dave. This is the code that I am running in the Form
> > > now:
> > > Private Sub cboEmployee_AfterUpdate()
> > > 'After selecting user name set focus to password field
> > > Me.txtPassword.SetFocus
> > >
> > > Dim strSQL As String
> > >
> > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > Me.cboEmployee & """ AS text;"
> > >
> > > End Sub
> > >
> > > The error is gone, but now nothing happens. The CurrentUser in
> > > tblLoginSettings stays the same. The value from the ComboBox is never
> > > actually passed. I know VBA in Excel pretty well, but I don't know VBA in
> > > Access well. The code looks right to me, but I just can't tell what is
> > > wrong. Perhaps it could be a setting somewhere...on the Form on in the
> > > tlbLoginSettings? I think we car egetting very close to a solution here.
> > > Any additional thoughts on this?
> > >
> > > Thanks for your time,
> > > Ryan--
> > >
> > >
> > >
> > > --
> > > RyGuy
> > >
> > >
> > > "Klatuu" wrote:
> > >
> > > > My mistake, sorry. Should be:
> > > > strSQL = "INSERT INTO tblLoginSettings (CurrentUser) SELECT """ & _
> > > > Me.MyCombName & """ AS dummy;"
> > > >
> > > > --
> > > > Dave Hargis, Microsoft Access MVP
> > > >
> > > >
> > > > "ryguy7272" wrote:
> > > >
> > > > > Running the code below gives me a syntax error:
> > > > > Private Sub cboEmployee_AfterUpdate()
> > > > > 'After selecting user name set focus to password field
> > > > > Me.txtPassword.SetFocus
> > > > >
> > > > > Dim strSQL As String
> > > > >
> > > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > > Me.cboEmployee & """ AS dummy;"
> > > > > CurrentDb.Execute strSQL, dbFailOnError
> > > > >
> > > > > End Sub
> > > > >
> > > > >
> > > > > Error is:
> > > > > Run-time error 3134:
> > > > > Syntax Error in INSERT INTO statement.
> > > > >
> > > > > This line is highlighted:
> > > > > CurrentDb.Execute strSQL, dbFailOnError
> > > > >
> > > > > What causes this error?
> > > > >
> > > > > Regards,
> > > > > Ryan---
> > > > >
> > > > > --
> > > > > RyGuy
> > > > >
> > > > >
> > > > > "ryguy7272" wrote:
> > > > >
> > > > > > Thanks for the look Dave! The code looks like it should work, but it
> > > > > > actually does not work.
> > > > > >
> > > > > > The error message reads:
> > > > > > Compile Error:
> > > > > > Method or Data Member not Found
> > > > > >
> > > > > > The Private line is yellow and the following is highlighted:
> > > > > > .MyCombName
> > > > > >
> > > > > >
> > > > > > Yes, CurrentUser is of Data Type text.
> > > > > >
> > > > > > The Row Source on the ComboBox is:
> > > > > > SELECT DISTINCT tblLogin.Login FROM tblLogin ORDER BY tblLogin.Login;
> > > > > >
> > > > > > Also, After Update is set to:
> > > > > > [Event Procedure]
> > > > > > (not sure if that makes a difference or not...)
> > > > > >
> > > > > > The code under the UserForm is as follows;
> > > > > > 'Private Sub cboEmployee_BeforeUpdate(Cancel As Integer)
> > > > > > Private Sub cboEmployee_AfterUpdate()
> > > > > > 'After selecting user name set focus to password field
> > > > > >
> > > > > > Dim strSQL As String
> > > > > >
> > > > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > > > Me.MyCombName & """ AS dummy;"
> > > > > > CurrentDb.Execute strSQL, dbFailOnError
> > > > > >
> > > > > > Me.txtPassword.SetFocus
> > > > > >
> > > > > > End Sub
> > > > > >
> > > > > > Any additional thoughts?
> > > > > > Thanks,
> > > > > > Ryan---
> > > > > >
> > > > > >
> > > > > > --
> > > > > > RyGuy
> > > > > >
> > > > > >
> > > > > > "Klatuu" wrote:
> > > > > >
> > > > > > > I assume the combo box will be an unbound control and that tblLoginSettings
> > > > > > > is not part of the form's record source. Use the combo's After Update event:
> > > > > > >
> > > > > > > Dim strSQL As String
> > > > > > >
> > > > > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > > > > Me.MyCombName & """ AS dummy;"
> > > > > > > Currentdb.Execute strSQL, dbFailOnError
> > > > > > >
> > > > > > > The above syntax assumes CurrentUser is a text field.
> > > > > > > --
> > > > > > > Dave Hargis, Microsoft Access MVP
> > > > > > >
> > > > > > >
> > > > > > > "ryguy7272" wrote:
> > > > > > >
> > > > > > > > I’d like to take a value from a combo box and load it into a table named
> > > > > > > > tblLoginSettings. I am trying to figure out how to get the value into a
> > > > > > > > field named ‘CurrentUser’ into the table named tblLoginSettings. Not sure
> > > > > > > > how to start. I guess it would be done by passing a variable, or passing a
> > > > > > > > parameter, or something like that. Can someone give me some code to do this,
> > > > > > > > or refer me to a web site that ex\plains how to do this?
> > > > > > > >
> > > > > > > > Thanks so much,
> > > > > > > > Ryan---
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > RyGuy

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      22nd May 2008
Sure. I’d certainly appreciate any and all help with this! Basically, under
Tools > Startup, I have Display Form/Page, which shows frmLogon. This forces
this particular Form to show when Access starts up. Pretty basic stuff,
right. So now, with the Tables and other things hidden, only that Form
shows. On the frmLogon, I have a ComboBox, named ‘cboEmployee’, which loads
names from Row Source ‘SELECT DISTINCT tblLogin.Login FROM tblLogin ORDER BY
tblLogin.Login;’. Pretty basic, right. This Form has a TextBox, where a
user can input their password. The Form also has a command button, named
‘cmdLogin’. Based on the user and the password, one of two forms opens, and
will eventually display links certain reports. Anyway, I’m trying to get the
user, from the ComboBox, into a Table, named ‘tblLoginSettings’.
‘tblLoginSettings’ consists of only a FieldName ‘ID’, which is Data Type
AutoNumber, and FieldName ‘Current User’, which is Data Type text. I was
hoping to be able to pass the variable from the ComboBox, named ‘cboEmployee’
to the ‘tblLoginSettings’ in the CurrentUser Field. Let’s say, for instance,
asmith is selected from the ComboBox, how can I transfer that variable to the
Table ‘tblLoginSettings’ and the Field ‘CurrentUser’? I guess it is kind of
complex. I’m not sure Access can do this, but I’ll bet it can…

It seems like you gave me the code to build that string. How do i pass that
value to the 'CurrentUser' Field in the ‘tblLoginSettings' Table? I’d
appreciate any help that you could offer on this.


Regards,
Ryan---


--
RyGuy


"Klatuu" wrote:

> Can you describe what is it you want to do? I guess I am not clear on the
> intent. If you can tell me what, perhaps I can tell you how.
> --
> Dave Hargis, Microsoft Access MVP
>
>
> "ryguy7272" wrote:
>
> > Oh! It's starting to make sense. Maybe I need to use a Query, rather than a
> > Table. Right now I have a Table named tblLoginSettings. It has a Field,
> > which is Data Type AutoNumber and another Field, which is Date Type Text.
> > That's all. i don't use a Query for this. Should l I use a Query for this?
> > I only have two Queries in this DB and they are actually related to this
> > Table. I was hoping to get the value from the ComboBox, pass it to the
> > Table, named tblLoginSettings, and pass that to one of the two Queries,
> > depending on what is entered into the Table. Does that make any sense? Is
> > there a better way of doing this?
> >
> > Please let me know what to do.
> >
> >
> > Thanks,
> > Ryan--
> >
> > --
> > RyGuy
> >
> >
> > "Klatuu" wrote:
> >
> > > You are not executing the SQL. All you are doing is building the SQL command.
> > > Should be:
> > >
> > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > Me.cboEmployee & """ AS text;"
> > >
> > > Currentdb.Execute strSQL, dbFailOnError
> > >
> > > --
> > > Dave Hargis, Microsoft Access MVP
> > >
> > >
> > > "ryguy7272" wrote:
> > >
> > > > Thanks for following up Dave. This is the code that I am running in the Form
> > > > now:
> > > > Private Sub cboEmployee_AfterUpdate()
> > > > 'After selecting user name set focus to password field
> > > > Me.txtPassword.SetFocus
> > > >
> > > > Dim strSQL As String
> > > >
> > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > Me.cboEmployee & """ AS text;"
> > > >
> > > > End Sub
> > > >
> > > > The error is gone, but now nothing happens. The CurrentUser in
> > > > tblLoginSettings stays the same. The value from the ComboBox is never
> > > > actually passed. I know VBA in Excel pretty well, but I don't know VBA in
> > > > Access well. The code looks right to me, but I just can't tell what is
> > > > wrong. Perhaps it could be a setting somewhere...on the Form on in the
> > > > tlbLoginSettings? I think we car egetting very close to a solution here.
> > > > Any additional thoughts on this?
> > > >
> > > > Thanks for your time,
> > > > Ryan--
> > > >
> > > >
> > > >
> > > > --
> > > > RyGuy
> > > >
> > > >
> > > > "Klatuu" wrote:
> > > >
> > > > > My mistake, sorry. Should be:
> > > > > strSQL = "INSERT INTO tblLoginSettings (CurrentUser) SELECT """ & _
> > > > > Me.MyCombName & """ AS dummy;"
> > > > >
> > > > > --
> > > > > Dave Hargis, Microsoft Access MVP
> > > > >
> > > > >
> > > > > "ryguy7272" wrote:
> > > > >
> > > > > > Running the code below gives me a syntax error:
> > > > > > Private Sub cboEmployee_AfterUpdate()
> > > > > > 'After selecting user name set focus to password field
> > > > > > Me.txtPassword.SetFocus
> > > > > >
> > > > > > Dim strSQL As String
> > > > > >
> > > > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > > > Me.cboEmployee & """ AS dummy;"
> > > > > > CurrentDb.Execute strSQL, dbFailOnError
> > > > > >
> > > > > > End Sub
> > > > > >
> > > > > >
> > > > > > Error is:
> > > > > > Run-time error 3134:
> > > > > > Syntax Error in INSERT INTO statement.
> > > > > >
> > > > > > This line is highlighted:
> > > > > > CurrentDb.Execute strSQL, dbFailOnError
> > > > > >
> > > > > > What causes this error?
> > > > > >
> > > > > > Regards,
> > > > > > Ryan---
> > > > > >
> > > > > > --
> > > > > > RyGuy
> > > > > >
> > > > > >
> > > > > > "ryguy7272" wrote:
> > > > > >
> > > > > > > Thanks for the look Dave! The code looks like it should work, but it
> > > > > > > actually does not work.
> > > > > > >
> > > > > > > The error message reads:
> > > > > > > Compile Error:
> > > > > > > Method or Data Member not Found
> > > > > > >
> > > > > > > The Private line is yellow and the following is highlighted:
> > > > > > > .MyCombName
> > > > > > >
> > > > > > >
> > > > > > > Yes, CurrentUser is of Data Type text.
> > > > > > >
> > > > > > > The Row Source on the ComboBox is:
> > > > > > > SELECT DISTINCT tblLogin.Login FROM tblLogin ORDER BY tblLogin.Login;
> > > > > > >
> > > > > > > Also, After Update is set to:
> > > > > > > [Event Procedure]
> > > > > > > (not sure if that makes a difference or not...)
> > > > > > >
> > > > > > > The code under the UserForm is as follows;
> > > > > > > 'Private Sub cboEmployee_BeforeUpdate(Cancel As Integer)
> > > > > > > Private Sub cboEmployee_AfterUpdate()
> > > > > > > 'After selecting user name set focus to password field
> > > > > > >
> > > > > > > Dim strSQL As String
> > > > > > >
> > > > > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > > > > Me.MyCombName & """ AS dummy;"
> > > > > > > CurrentDb.Execute strSQL, dbFailOnError
> > > > > > >
> > > > > > > Me.txtPassword.SetFocus
> > > > > > >
> > > > > > > End Sub
> > > > > > >
> > > > > > > Any additional thoughts?
> > > > > > > Thanks,
> > > > > > > Ryan---
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > RyGuy
> > > > > > >
> > > > > > >
> > > > > > > "Klatuu" wrote:
> > > > > > >
> > > > > > > > I assume the combo box will be an unbound control and that tblLoginSettings
> > > > > > > > is not part of the form's record source. Use the combo's After Update event:
> > > > > > > >
> > > > > > > > Dim strSQL As String
> > > > > > > >
> > > > > > > > strSQL = "INSERT tblLoginSettings (CurrentUser) SELECT """ & _
> > > > > > > > Me.MyCombName & """ AS dummy;"
> > > > > > > > Currentdb.Execute strSQL, dbFailOnError
> > > > > > > >
> > > > > > > > The above syntax assumes CurrentUser is a text field.
> > > > > > > > --
> > > > > > > > Dave Hargis, Microsoft Access MVP
> > > > > > > >
> > > > > > > >
> > > > > > > > "ryguy7272" wrote:
> > > > > > > >
> > > > > > > > > I’d like to take a value from a combo box and load it into a table named
> > > > > > > > > tblLoginSettings. I am trying to figure out how to get the value into a
> > > > > > > > > field named ‘CurrentUser’ into the table named tblLoginSettings. Not sure
> > > > > > > > > how to start. I guess it would be done by passing a variable, or passing a
> > > > > > > > > parameter, or something like that. Can someone give me some code to do this,
> > > > > > > > > or refer me to a web site that ex\plains how to do this?
> > > > > > > > >
> > > > > > > > > Thanks so much,
> > > > > > > > > Ryan---
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > RyGuy

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameter Query with Parameter value(s) or no entry returns all =?Utf-8?B?QmV0dGVyZ2FpbnM=?= Microsoft Access 3 17th Aug 2011 04:33 PM
Parameter Query help - Not passing parameter? Marc T Microsoft Access Queries 3 14th Sep 2009 04:21 PM
Passing parameter to query without using Enter Parameter window Mike P Microsoft Access VBA Modules 3 23rd Dec 2007 08:53 PM
passing any object as parameter to a function which takes Object class as parameter and fetching the members at runtime Ram Microsoft VB .NET 5 11th Oct 2005 08:24 PM
error STOP:0x0000007B (parameter, parameter, parameter, parameter) robert35 Microsoft Access Getting Started 1 15th Dec 2004 04:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:02 AM.